package com.example.designpattenexample.mediator;

import java.util.ArrayList;
import java.util.List;

public class MarriageAgencyImpl implements MarriageAgency {

    private List<Men> mens = new ArrayList<>();
    private List<Women> womens = new ArrayList<>();
    private List<Person> targetPerson = new ArrayList<>();

    @Override
    public void register(Person person) {
        if (person.sex == Sex.MALE)
            mens.add((Men) person);
        else if (person.sex == Sex.FEMALE)
            womens.add((Women) person);
    }

    @Override
    public void pair(Person person) {
        if (person.sex == Sex.MALE){
            targetPerson.addAll(womens);
        }else if (person.sex == Sex.FEMALE){
            targetPerson.addAll(mens);
        }
        pairByAge(targetPerson,person);
    }

    private void pairByAge(List<Person> target, Person person) {
        target.stream().forEach(t->{
            if (t.age == person.requestAge){
                System.out.println(person.name + " 匹配" + t.name + " 成功！");
            }
        });
    }
}
